﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <button onclick="changeValue();">Change Value</button>
    <button onclick="searchValue();">Search</button>
		<script type="text/javascript">
		    localStorage.clear();
		    console.log(localStorage);
		    if (window.addEventListener)
		        window.addEventListener('storage', storage_event, false);
		    else if (window.attachEvent) // IE
		        window.attachEvent('onstorage', storage_event, false);
		    function storage_event(event) {
		        console.log(event);
		    }
		    function changeValue() {
		        localStorage.myValue = Math.random();
		    }

		    Storage.prototype.search = function (keyword) {
		        var array = new Array();
		        var re = new RegExp(keyword, "gi");
		        for (var i = 0; i < this.length; i++) {
		            var value = this.getItem(this.key(i));
		            if (value.search(re) > -1)
		                array.push(value);
		        }
		        return array;
		    }

		    function searchValue() {
		        var arr = localStorage.search('32');
		        if (arr.length > 0)
		            alert("found");
		        else
		            alert("not find");
		    }
		</script>
</body>
</html>
